package com.sinai.mshab.client.widgets;

import java.util.ArrayList;

import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.sinai.mshab.client.util.Observable;
import com.sinai.mshab.client.util.Observer;

/**
 * Creates a logoff page. When this page is loaded, observers of this page are
 * notified.
 * 
 * @author serge
 * 
 */
public class LogoffLink extends Label implements Observable {

	private ArrayList<Observer> observers = new ArrayList<Observer>();
	private String historyToken;

	/**
	 * Creates a new logoff page
	 * 
	 * @param text
	 *            the text to put in the label
	 * @param ob
	 *            the observer
	 */
	public LogoffLink(String text, Observer ob) {
		this.setText(text);
		addClickListener(new LogoffListner());
		observers.add(ob);
	}

	public void addObserver(Observer o) {
		observers.add(o);
	}

	public void notifyObservers() {
		for (int i = 0; i < observers.size(); i++) {
			observers.get(i).update(this, "logoff");
		}
	}

	private class LogoffListner implements ClickListener {
		public void onClick(Widget sender) {
			notifyObservers();
		}
	}
}
